require('./PageDetailflow.styl');
import { Control } from 'react-keeper';
const reactMixin = require('react-mixin');
const Actions = require('./actions');
const Store = require('./store');
const DetailFlow = require('components/detailwrap');
const WithList = require('components/withlist');
const DetailList = require('components/pendinglist')
const classNames = require("classnames");

class Detailflow extends React.Component {

    constructor(props) {
        super(props);
        this.state = {
            head: {}, //{ name: "", statue: "" },
            item: { sender: "", begin_date: "", approvers: [{ ender: "", statue: "", end_date: "", process_result: { content: '' } }] },
            content: [],
            foot_btns: ["同意", "拒绝", "评论"],
            tool: '',
            finish_time: '',
            process_result: '',
            next_cursor: 0,
            attachment: [],
            proj_name: '',
            proj_num: '',
            origin: '',
            cc_list: '',
            form_component_values: {},
            date: new Date(),//定时器
            paypointerNum: 1,
            payPointerCurrNum: 0,
            unionid: [],//项目参与者unionid
            originator_user_id: '',
            file_id: ''
        };
        this.handleSuggestion = this.handleSuggestion.bind(this);
    }
    handleSuggestion(index) {
        let process_id = Control.state.process_id;
        let module_type = this.state.module_type;
        Control.go('/home/workplan/pending/detail/true/suggestion', { folder_id: this.state.folder_id, cc_list: this.state.cc_list, form_component_values: this.state.form_component_values, proj_name: this.state.proj_name, proj_num: this.state.proj_num, sender: this.state.item.sender, approvers: this.state.item.approvers, process_result: this.state.process_result, index, process_id, payplanId: this.state.payplanId, origin: module_type, proj_type: this.state.proj_type, finish_time: this.state.finish_time, next_cursor: this.state.next_cursor, payPointerCurrNum: this.state.payPointerCurrNum, paypointerNum: this.state.paypointerNum, approvers_id: this.state.approvers_id, cc_list_id: this.state.cc_list_id, originator_user_id: this.state.originator_user_id })
    }
    //定时器
    tick() {
        this.setState({
            date: new Date()
        });
    }
    render() {
        let t = this;
        if (!this.state.head.hasOwnProperty("name")) {
            return (null)
        } else {
            return (
                <div className="detailflow">
                    <DetailFlow.head {...t.state.head} />
                    <div className="line"></div>
                    <DetailList data={this.state.content} className="workplan-manage" norefresh={true} />
                    {this.state.attachment.length != 0 && <DetailFlow.attachment attachment={JSON.stringify(this.state.attachment)} />}
                    {/* <ListWithDetail className="workplan-manage" /> */}
                    <DetailFlow.item {...t.state.item} />
                    {this.state.tool && <div className="line2"></div>}
                    {this.state.tool && <DetailFlow.foot footBtns={this.state.foot_btns} cb={this.handleSuggestion} />}
                </div>
            );
        }

        // <DetailList data={this.state.content} className="workplan-manage"/>
    }

    componentWillMount() {

    }

    componentDidMount() {
        let process_id = Control.state.process_id;
        let origin = Control.state.origin;
        Actions.query({ process_id, origin });//, tool: this.props.params.tool
        // this.timerID = setInterval(
        //     () => this.tick(),
        //     60 * 1000
        // );
    }

    componentWillReceiveProps(nextProps) {

    }

    shouldComponentUpdate(nextProps, nextState) {
        return true;
    }

    componentWillUpdate(nextProps, nextState) {
    }

    componentDidUpdate(prevProps, prevState) {

    }

    componentWillUnmount() {
        clearInterval(this.timerID);
    }
}

reactMixin.onClass(Detailflow, Reflux.connect(Store));

module.exports = Detailflow;
